@extends('Shop.index')

@section('content')
<!--aside nav-->
<!--aside nav-->
<section class="rt_wrap content mCustomScrollbar">
 <div class="rt_content">
      <div class="page_title">
       <h2 class="fl">商品列表示例</h2>
       <a href="/goods/add" class="fr top_rt_btn add_icon">添加商品</a>
      </div>  
      <section class="mtb">
       <form action="/goods/list">
         <input type="text" class="textbox textbox_225" name="keywords" value="{{$data->keywords or ''}}" placeholder="输入产品关键词...">
         <input type="submit" value="查询" class="group_btn">
       </form>
      </section>
        <div class="mws-form-message error hide">
            
        </div>
        <div class="mws-form-message success hide">

        </div>
      <table class="table">
       <tbody>
       @if (count($errors) > 0)
          <div class="mws-form-message error">
                <ul>
                  @foreach ($errors->all() as $error)
                      <li>{{ $error }}</li>
                  @endforeach
                    
                </ul>
            </div>
      @endif
       <tr>
        <th>缩略图</th>
        <th>产品名称</th>
        <th>单价</th>
        <th>热销</th>
        <th>上架</th>
        <th>库存</th>
        <th>操作</th>
       </tr>
       @foreach($goods as $k => $v)
       <tr>
        <td class="center"><img src="{{$v->cover}}" width="50" height="50" class="mCS_img_loaded"></td>
        <td>{{$v->spname}}</td>
        <td class="center"><strong class="rmb_icon">{{$v->price}}</strong></td>
        <td class="center"><a title="{{$v->hot}}" v="{{$v->id}}" class="link_icon hot">@if($v->hot =='1')Y @else X @endif</a></td>
        <td class="center"><a title="{{$v->status}}" v="{{$v->id}}" class="link_icon status" >@if($v->status =='1')Y @else X @endif</a></td>
        <td class="center">{{$v->count}}</td>
        <td class="center">
         <a href="/goods/edit/{{$v->id}}" title="编辑" class="link_icon">e</a>
         <a href="/goods/delete/{{$v->id}}" title="删除" class="link_icon">d</a>
        </td>
       </tr>
       @endforeach
      </tbody></table>
      <aside class="paging">
       <a>第一页</a>
       <a>1</a>
       <a>2</a>
       <a>3</a>
       <a>…</a>
       <a>1004</a>
       <a>最后一页</a>
      </aside>
      <aside class="paging">
      {!! $goods->appends($data)->render() !!}
      </aside>
 </div>
</section>
@endsection
@section('js')
<script src="/shopadmin/js/ueditor.config.js"></script>
<script src="/shopadmin/js/ueditor.all.min.js"> </script>
<script>
    $(function(){
      $('.status').click(function(){

          //获取元素,获取元素的状太 并转换
          var aa = $(this);
          var status =status($(this).attr('title'));
          $(this).removeAttr('title');
          $(this).attr('title',status);
          function status($a){
          if($a=='0'){return 1;}else{return 0;};
          }
          if(status==1){
              aa.html('Y');
          }else{
              aa.html('X');
          }
           //获取id
          var id = $(this).attr('v');
          //发送ajxa
          $.get('/goods/update', {'status':status,'id':id},function(data){
            
              if(data==1){
                  success('更新成功');
                  
              }else{
                  success('更新失败');
              }
          });   
          
      })

      $('.hot').click(function(){

          //获取元素,获取元素的状太 并转换
          var bb = $(this);
          var status =status($(this).attr('title'));
          $(this).removeAttr('title');
          $(this).attr('title',status);
          function status($a){
          if($a=='0'){return 1;}else{return 0;};
          }
          if(status==1){
              bb.html('Y');
          }else{
              bb.html('X');
          }
           //获取id
          var id = $(this).attr('v');
          //发送ajxa
          $.get('/goods/updatehot', {'hot':status,'id':id},function(data){
            
              if(data==1){
                  success('更新成功');
                  
              }else{
                  success('更新失败');
              }
          });   
          
      })


      function success(str)
      {   
          //将字符串放到div中
          $('.success').html(str);
          //显示元素
          $('.success').show();
          setTimeout(function(){
              $('.success').fadeOut();
          },3000);
      }
      function error(str)
      {   
          //将字符串放到div中
          $('.error').html(str);
          //显示元素
          $('.error').show();
          setTimeout(function(){
              $('.error').fadeOut();
          },3000);
      }
  }); 

</script>
@endsection